<?php

class admin extends CI_controller {
    
    /**
     * Index
     * 
     * Make sure the dashboard gets loaded first when the user is logged in
     */
    public function index() {
		parent::__construct();
		
		// get the username
		$username = $this->session->userdata['username'];
		
		// set some variables
		$data = array(
			'main_content' => 'admin/dashboard'
		);
		
        $this->load->view('admin/template.php', $data);
    }
	
	
	public function user_settings($function = false, $data = array('notification' => null)) {
		
		// get the username
		$username = $this->session->userdata['username'];
		
		// save the user settings
		if ($function == 'save') {
			$post = $this->input->post();
			// check if the form realy is submitted
			if (!empty($post)) {
				$this->load->model('user_settings');
				$save = $this->user_settings->save_userdata($username);
				
				if (!$save)
					$data['notification'] = array('type' => 'error', 'message' => 'Er is iets misgegaan bij het opslaan van uw gegevens!');
				else
					$data['notification'] = array('type' => 'success', 'message' => 'Uw gegevens zijn succesvol opgeslagen');
				
				$this->user_settings(false, $data);
				return;
			}
		}
		
		// include the user controller
		include_once 'user.php';
		// create a new user object
		$user = new User($username);
		
		// get the userdata
		$data['userdata'] = $user->get_userdata();
		// set the main_content
		$data['main_content'] = 'admin/user_settings';
		
		// load the settings view
		$this->load->view('admin/template', $data);
	}
}